package com.htl.实用类;

public class String__method {
    public static void main(String[] args) {
        char[] array =
                {'J','a','v','a',',','H','e','l','l','o',',','W','o','r','l','d'};
        String str = new String(array);
        String str1 = "Java,Hello,World";
        //intern方法是将字符串对象复制到字符串常量池中，并返回常量池的引用
        String intern = str.intern();
        System.out.println(intern == str1); //true
        System.out.println(intern);     //Java,Hello,World
        System.out.println(str);        //Java,Hello,World
        //获取字符串的长度
        System.out.println(str.length());   //16
        //判断字符串是否为空
        System.out.println(str.isEmpty());  //false
        //下标为2的字符
        System.out.println(str.charAt(2));  //v
        //H的下标
        System.out.println(str.indexOf("H")); //5
        String str2 = "Hello";
        String str3 = "HELLO";
        //忽略大小写判断字符串是否相等
        System.out.println(str2.equalsIgnoreCase(str3)); //true
        //是否以Java开头
        System.out.println(str.startsWith("Java")); //true
        //是否以Java结尾
        System.out.println(str.endsWith("Java"));   //false
        //从2开始截取到结尾
        System.out.println(str.substring(2));   //va,Hello,World
        //从2开始截取到6，左开右闭
        System.out.println(str.substring(2, 6));//va,H
        //World替换成Java
        System.out.println(str.replaceAll("World", "Java"));//Java,Hello,Java
        //用逗号分割字符串
        String[] split = str.split(",");
        System.out.println(split[0]);   //Java
        System.out.println(split[1]);   //Hello
        System.out.println(split[2]);   //World
        //转为字符数组
        char[] chars = str.toCharArray();
        System.out.println(chars[3]);   //a
        //转大写
        System.out.println(str2.toUpperCase()); //HELLO
        //转小写
        System.out.println(str3.toLowerCase()); //hello
    }
}
